package com.ksd.modules.advert.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ksd.common.annotation.ApiLog;
import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.common.enums.DeletedEnums;
import com.ksd.common.po.BatchIdsPO;
import com.ksd.common.web.annotation.RepeatSubmit;
import com.ksd.modules.advert.entity.AdminAdvert;
import com.ksd.modules.advert.po.AdminAdvertSavePO;
import com.ksd.modules.advert.po.AdminAdvertSearchPO;
import com.ksd.modules.advert.service.IAdminAdvertService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 广告 前端控制器
 * </p>
 *
 * @author Auto Generator
 * @since 2023-08-16
 */
@RestController
public class AdminAdvertController extends BaseController {

    @Autowired
    private IAdminAdvertService adminAdvertService;

    /**
     * 查询首页有广告接口
     *
     * @param adminAdvertSearchPO
     * @return
     */
    @PostMapping("/adverts/list")
    public R<Page<AdminAdvert>> findAdvertiser(@Validated @RequestBody AdminAdvertSearchPO adminAdvertSearchPO) {
        adminAdvertSearchPO.setDeleted(DeletedEnums.UN_DELETED.getCode());
        return R.data(adminAdvertService.findAdvert(adminAdvertSearchPO));
    }

    /**
     * 保存和更新
     *
     * @param adminAdvertSavePO
     * @return
     */
    @PostMapping("/adverts/saveupdate")
    @ApiLog("保存和更新广告")
    @RepeatSubmit
    public R<Boolean> saveUpdateAdvertiser(@Validated @RequestBody AdminAdvertSavePO adminAdvertSavePO) {
        return R.data(adminAdvertService.saveUpdateAdvert(adminAdvertSavePO));
    }

    /**
     * 根据id查询广告
     *
     * @param id
     * @return
     */
    @PostMapping("/adverts/get/{id}")
    public R<AdminAdvert> getAdvertiserById(@PathVariable("id") Long id) {
        return R.data(adminAdvertService.getAdvertById(id));
    }

    /**
     * 修改状态
     *
     * @return
     */
    @PostMapping("/adverts/status/{id}/{field}/{value}")
    @ApiLog("广告修改状态")
    @RepeatSubmit
    public R<Boolean> updateStatus(
            @PathVariable("id") Long id,
            @PathVariable("field") String field,
            @PathVariable("value") Integer value
    ) {
        return R.data(adminAdvertService.updateStatus(id, field, value));
    }


    /**
     * 修改位置
     *
     * @return
     */
    @PostMapping("/adverts/changesort/{id}/{sorted}")
    @ApiLog("广告位置调整")
    @RepeatSubmit
    public R changeCategoryAdvertSort(@PathVariable("id") Long id,
                                      @PathVariable("sorted") Integer sorted) {
        return R.data(adminAdvertService.changeCategoryAdvertSort(id, sorted));
    }


    /**
     * 查询首页有广告接口
     *
     * @param adminAdvertSearchPO
     * @return
     */
    @PostMapping("/adverts/recyle")
    public R<Page<AdminAdvert>> findAdvertiserRecyle(@Validated @RequestBody AdminAdvertSearchPO adminAdvertSearchPO) {
        adminAdvertSearchPO.setDeleted(DeletedEnums.DELETED.getCode());
        return R.data(adminAdvertService.findAdvert(adminAdvertSearchPO));
    }

    /**
     * 批量逻辑删除
     *
     * @return
     */
    @PostMapping("/adverts/batch/dels")
    @ApiLog("批量逻辑删除")
    @RepeatSubmit
    @ApiOperation("批量逻辑删除")
    public R<Boolean> batchDels(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminAdvertService.bacthDels(batchIdsPO));
    }

    /**
     * 批量逻辑恢复
     *
     * @return
     */
    @PostMapping("/adverts/batch/recover")
    @ApiLog("批量逻辑恢复")
    @RepeatSubmit
    @ApiOperation("批量逻辑恢复")
    public R<Boolean> batchRecovers(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminAdvertService.batchRecovers(batchIdsPO));
    }


    /**
     * 批量彻底删除
     *
     * @return
     */
    @PostMapping("/adverts/batch/remove")
    @ApiLog("批量彻底删除")
    @RepeatSubmit
    @ApiOperation("批量彻底删除")
    public R<Boolean> batchRemoves(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminAdvertService.batchRemoves(batchIdsPO));
    }

    /**
     * 逻辑删除
     *
     * @param id
     * @return
     */
    @PostMapping("/adverts/del/{id}")
    @ApiLog("逻辑删除")
    @RepeatSubmit
    public R<Boolean> delAdvertiserById(@PathVariable("id") Long id) {
        return R.data(adminAdvertService.deleteAdvertById(id));
    }


    /**
     * 彻底删除
     *
     * @param id
     * @return
     */
    @PostMapping("/adverts/remove/{id}")
    @ApiLog("根据id彻底删除")
    @RepeatSubmit
    public R<Boolean> removeAdvertiserById(@PathVariable("id") Long id) {
        return R.data(adminAdvertService.removeAdvertById(id));
    }

    /**
     * 恢复删除
     *
     * @param id
     * @return
     */
    @PostMapping("/adverts/recover/{id}")
    @ApiLog("根据id恢复删除")
    @RepeatSubmit
    public R<Boolean> recoverAdvertiserById(@PathVariable("id") Long id) {
        return R.data(adminAdvertService.recoverAdvertById(id));
    }


    /**
     * 【广告】-  复制数据
     * @param opid
     * @return
     */
    @PostMapping("/adverts/copy/{opid}")
    @ApiLog("【广告】- 复制数据")
    @RepeatSubmit
    public R<Boolean> copyData(@PathVariable("opid")Long opid){
        return R.data(adminAdvertService.copyData(opid));
    }
}
